
package cn.gz3c.uitest.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;

import androidx.lifecycle.LifecycleOwner;

import com.huawei.hms.audioeditor.sdk.asset.HAEAsset;
import com.huawei.hms.audioeditor.sdk.asset.HAEAudioAsset;
import com.huawei.hms.audioeditor.sdk.effect.HAEEffect;
import com.huawei.hms.audioeditor.ui.p.t.b;

import java.util.Iterator;

import cn.gz3c.uitest.viewmodel.EditPreviewViewModel;
import cn.gz3c.uitest.t;

public class NormalLineView extends View {
    private t.c a;
    private int b;
    private int c = 0;
    private int d;
    private double e;
    private EditPreviewViewModel f;
    private boolean g = true;

    public NormalLineView(Context var1, EditPreviewViewModel var2) {
        super(var1);
        this.f = var2;
        LifecycleOwner var3;
        var2.n().observe(var3 = (LifecycleOwner) var1, (var1x) -> {
            this.e = var1x;
            this.post(this::invalidate);
        });
        this.f.m().observe(var3, (var1x) -> {
            this.d = var1x;
            this.post(this::invalidate);
        });
    }

    protected void onMeasure(int var1, int var2) {
        super.onMeasure(var1, var2);
        if (this.a != null) {
            var1 = this.getMeasuredWidth();
            t.c var5;
            t.c var10000 = var5 = this.a;
            int var3 = 0;
            Iterator var4 = var10000.a.iterator();

            while (var4.hasNext()) {
                if (((b) var4.next()).a.size() > 0) {
                    var3 = 1;
                    break;
                }
            }

            Iterator var6 = var5.b.iterator();

            while (var6.hasNext()) {
                if (((b) var6.next()).b.size() > 0) {
                    ++var3;
                    break;
                }
            }

            this.setMeasuredDimension(var1, com.huawei.hms.audioeditor.ui.common.utils.a.a(5.0F) * var3);
        }
    }

    protected void onDraw(Canvas var1) {
        super.onDraw(var1);
        ((MarginLayoutParams) this.getLayoutParams()).setMargins(com.huawei.hms.audioeditor.ui.common.utils.a.a(18.0F), 0, 0, 0);
        this.post(this::requestLayout);
        this.c = 6;
        byte var2;
        String var3;
        t.c var4;
        int var7;
        Iterator var13;
        Paint var16;
        Paint var10001;
        int var22;
        if (this.g) {
            var2 = 1;
            var3 = "#FF4ABEA1";
            if (this.b != var2 && (var4 = this.a) != null && var4.a(var2).size() != 0) {
                var10001 = var16 = new Paint();
                var10001.setColor(Color.parseColor(var3));
                Paint var14;
                var10001 = var14 = new Paint();
                var10001.setStrokeCap(Cap.ROUND);
                var10001.setColor(Color.parseColor("#FFD1A738"));
                var10001.setStyle(Style.FILL);
                var10001.setStrokeWidth((float) com.huawei.hms.audioeditor.ui.common.utils.a.a(4.0F));
                var13 = this.a.a(var2).iterator();

                label65:
                while (var13.hasNext()) {
                    Iterator var5 = ((b) var13.next()).a.iterator();

                    while (true) {
                        HAEAsset var6;
                        int var8;
                        float var9;
                        HAEAsset var10000;
                        HAEAudioAsset var20;
                        do {
                            if (!var5.hasNext()) {
                                continue label65;
                            }

                            var10000 = var6 = (HAEAsset) var5.next();
                            var7 = (int) ((double) var6.getStartTime() / com.huawei.hms.audioeditor.ui.common.utils.d.a(this.d) * this.e);
                            var8 = (int) ((double) var6.getDuration() / com.huawei.hms.audioeditor.ui.common.utils.d.a(this.d) * this.e);
                            int var10;
                            var1.drawRoundRect(new RectF(var9 = (float) var7, (float) (var10 = this.c), (float) (var7 + var8), (float) (com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F) + var10)), (float) com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F), (float) com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F), var16);
                        } while ((var20 = (HAEAudioAsset) var10000).getFootPrintList() == null);

                        Iterator var21 = var20.getFootPrintList().iterator();

                        while (var21.hasNext()) {
                            double var11 = (double) ((Float) var21.next() / var20.getSpeed() - (float) var6.getTrimIn()) / com.huawei.hms.audioeditor.ui.common.utils.d.a(this.d) * this.e;
                            if (0.0D <= var11 && (double) var8 >= var11) {
                                var1.drawPoint((float) var11 + var9, (float) this.c, var14);
                            }
                        }
                    }
                }

                var22 = this.c;
                this.c = com.huawei.hms.audioeditor.ui.common.utils.a.a(5.0F) + var22;
            }
        }

        var2 = 2;
        var3 = "#FFB96BCA";
        if (this.b != var2 && (var4 = this.a) != null && var4.a(var2).size() != 0) {
            var10001 = var16 = new Paint();
            var10001.setColor(Color.parseColor(var3));
            var13 = this.a.a(var2).iterator();

            while (var13.hasNext()) {
                Iterator var15 = ((b) var13.next()).b.iterator();

                while (var15.hasNext()) {
                    HAEEffect var17;
                    HAEEffect var23 = var17 = (HAEEffect) var15.next();
                    int var19 = (int) ((double) var23.getStartTime() / com.huawei.hms.audioeditor.ui.common.utils.d.a(this.d) * this.e);
                    int var18 = (int) ((double) (var23.getEndTime() - var17.getStartTime()) / com.huawei.hms.audioeditor.ui.common.utils.d.a(this.d) * this.e);
                    var1.drawRoundRect(new RectF((float) var19, (float) (var7 = this.c), (float) (var19 + var18), (float) (com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F) + var7)), (float) com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F), (float) com.huawei.hms.audioeditor.ui.common.utils.a.a(1.0F), var16);
                }
            }

            var22 = this.c;
            this.c = com.huawei.hms.audioeditor.ui.common.utils.a.a(5.0F) + var22;
        }

    }

    public void a(t.c var1, int var2) {
        this.a = var1;
        this.b = var2;
        this.post(this::invalidate);
    }
}
